<template>
  <div v-if="aeVo">
    <Form ref="frontConfigForm" :model="aeVo" :rules="ruleValidate" :label-width="80">
      <FormItem label="年级" prop="grade">
        <Select v-model="aeVo.grade" class="ml-5" style="width:200px;" placeholder="年级">
          <Option v-for="(g,index) in grades" :value="g" :key="index">{{ g + '级'}}</Option>
        </Select>
      </FormItem>
      <FormItem label="荣誉名称" prop="honourName">
        <Input v-model="aeVo.honourName" placeholder=""></Input>
      </FormItem>
      <FormItem label="学生姓名">
        <Input type="textarea" :rows="4" v-model="aeVo.studentsName" placeholder="请输入获奖学生名单"></Input>
      </FormItem>
    </Form>
  </div>
</template>

<script type="text/ecmascript-6">
  import Vue from 'vue'
  import {SERVICE_URLS} from "../../libs/service.url";

  export default {
    props: ['closeHandle', 'targetData'],
    components: {

    },
    data() {
      return {
        aeVo: null,
        grades : [
          2019,
          2018,
          2017,
          2016,
          2015,
          2014,
          2013,
          2012,
          2011,
          2010,
        ],
        ruleValidate: {
          grade: [
            {required: true,type:'number', message: '请选择年级！', trigger: 'change'}
          ],
          honourName: [
            {required: true, message: '荣誉名称不能为空！', trigger: 'blur'}
          ]
        },
        bIsAdd: false
      }
    },
    created() {
      if (this.targetData) {
        this.bIsAdd = false;
        this.aeVo = Object.assign({},this.targetData);
      } else {
        this.bIsAdd = true;
        this.aeVo = {
          id : '',
          grade : '',
          honourName : '',
          studentsName : ''
        }
      }
    },
    methods: {
      handleSubmit() {
        let self = this;
        this.$refs['frontConfigForm'].validate((valid) => {
          if (valid) {
            let url;
            if (self.bIsAdd) {
              url = SERVICE_URLS.flower.add;
            } else {
              url = SERVICE_URLS.flower.edit;
            }
            Vue.submit(self, {
              loading: 'loading',
              url: url,
              data: self.aeVo,
              callback: (_data) => {
                self.$Message.success('操作成功!');
                if (self.closeHandle) {
                  self.closeHandle();
                }
              }
            })
          } else {

          }
        });
      },
      logoUpdateHandle (val) {
        this.aeVo.logo = val;
      },
      handleReset() {
        this.$refs['frontConfigForm'].resetFields();
      },
      closeModal() {
        this.handleReset();
      }
    }
  }
</script>
